package org.itboys.trade.service;

import java.util.List;

import javax.annotation.Resource;

import org.itboys.mongodb.core.MongoDataSource;
import org.itboys.mongodb.service.BaseService;
import org.itboys.product.entity.ProductBrand;
import org.itboys.trade.entity.Cart;
import org.springframework.stereotype.Service;

import org.mongodb.morphia.query.Query;

@Service
public class CartService extends BaseService<Cart, Long>{
	
	@Resource(name = "orderDS")
	private MongoDataSource ds;

	@Override
	protected MongoDataSource getMongoDataSource() {
		return ds;
	}

	@Override
	protected Class<Cart> getEntityClass() {
		return Cart.class;
	}
	/**
	 * 根据cookiesId去查询列表
	 * @param cookiesId
	 * @return
	 */
	
	public List<Cart> getCartListByCookiesId(String cookiesId){
		List<Cart> cartList = ds.createQuery(Cart.class).filter("cookie", cookiesId).asList();
		return cartList;
	}
	/**
	 * 根据用户id去查询列表
	 * @param memberId
	 * @return
	 */
	public List<Cart> getCartListByMemberId(Long memberId){
		List<Cart> cartList = ds.createQuery(Cart.class).filter("memberId", memberId).asList();
		return cartList;
	}
	/**
	 * 获取购物车行
	 * @param cartId
	 * @return
	 */
	
	public Cart getCart(Long cartId){
		Cart cart = ds.createQuery(Cart.class).filter("id", cartId)
		.filter("deleted",false).get();
		return cart;
	}

}
